﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EginMahjong {

    private static EginMahjong _instance;
    public static EginMahjong Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new EginMahjong();
            }
            return _instance;
        }
    }
    public string weixin;
    public string android_url;
    public string iso_url;

    public int Avatar_id;
    public string nickname;
    public int uid;
    public SEX sex;
    public int coinCount;
    public float win_rate;
    public string GameType;
    public int openRoomId;
    public int gameRoomId;
    public int roomTypeId;
    public int totalRound;
    public ulong TimeStamp;//时间戳
    public SEAT_STATUS seatStatus;
    public string IP;
    //注册信息
    public string Registerphonenum;
    public int RegisteryanZhengCode;
    public string Registerusername;
    public string RegisterPassword;
    //暂时定义进入房间的信息
    public int CreatRoomTypeID;
    public int CteatrUid; //房主UID
    public int roomID;
    public int baseScore;
    public int seatID;
    public int Score;
    //公告
    public List<GameRollNoticeItem> NoticePb = new List<GameRollNoticeItem>();
    public bool haveNotice = false;

    //进入房间限制
    public Dictionary<int, int> dicRoomEnterLimit = new Dictionary<int, int>(); //房间1-6类型对应的最低进入房间的钱
    public Dictionary<int, int> dicRoomBaseScore = new Dictionary<int, int>();   //房间1-6类型对应的基础分数
    public Dictionary<int, int> dicRoomOnlineCount = new Dictionary<int, int>();   //房间1-6类型对应的基础分数
    public Dictionary<int, int> dicRoomBaseMaxScore = new Dictionary<int, int>(); //房间1-6类型对应的最大分数

    //加入房间后其他玩家信息(里面也包含自己的信息)
    public Dictionary<int, int> Otheruid = new Dictionary<int, int>();
    public Dictionary<int, int> OtherSeatId = new Dictionary<int, int>();
    public Dictionary<int, SEAT_STATUS> OtherSeatStatus = new Dictionary<int, SEAT_STATUS>();
    public Dictionary<int, SEX> OtherSex = new Dictionary<int, SEX>();
    public Dictionary<int, string> OtherIP = new Dictionary<int, string>();
    public Dictionary<int, int> OtherCoinCount = new Dictionary<int, int>();
    public Dictionary<int, int> OtherScore = new Dictionary<int, int>();
    public Dictionary<int, string> OtherNickName = new Dictionary<int, string>();
    public Dictionary<int, int> OtherAvatarid = new Dictionary<int, int>();
    public Dictionary<int, List<int>> OtherOutCardList = new Dictionary<int, List<int>>();  //重连后出的牌 OutCardList
    //
    public Dictionary<int, string> TempOtherNickName = new Dictionary<int, string>();
    public Dictionary<int, int> TempOtherAvatarid = new Dictionary<int, int>();
    //

    //结束游戏后存储信息
    public Dictionary<int, bool> OverRobot = new Dictionary<int, bool>();
    public Dictionary<int, int> OverRoundScore = new Dictionary<int, int>();
    public Dictionary<int, int> OverTotalScore = new Dictionary<int, int>();
    public Dictionary<int, int> OverRank = new Dictionary<int, int>();
    public Dictionary<int, List<int>> OverHandCardList = new Dictionary<int, List<int>>();
    public int readyCards;
    public Dictionary<int, List<int>> OverRecordList = new Dictionary<int, List<int>>();  //玩家战绩存储    重连 和 游戏结束都要存储
    public Dictionary<int, int> TotalScore = new Dictionary<int, int>(); //玩家战绩总分

    public Dictionary<int, int> OverLackMultiple = new Dictionary<int, int>();//缺几路
    public Dictionary<int, List<MahjongSpecialCardItem>> OverMahjongSpecialCard = new Dictionary<int, List<MahjongSpecialCardItem>>(); //每局结束特殊牌
    //重连第二步出牌
    public bool isSpecialPhases2 = false;

    //开始游戏后
    public int currentRound { get; set; }
    public int LastBankSid;
    public int bankerSid; //庄家位置
    public int turnSid { get; set; } //出牌玩家seatid
    public int remainCount { get; set; }
    public int handCard { get; set; } //游戏开始收到的庄家的第14张牌 摸到的牌
    public ROOM_STATUS roomStatus;
    public int nextSid { get; set; }// 该谁出牌
    public int LastNextSid { get; set; }  //上家出牌人nextSid

    public int LastSeatID { get; set; }    //上家的SeatID
    public int tempSeatId { get; set; }   //出牌人seatid
    public int turnCard { get; set; }//摸到的牌
    public int tableCard; //桌子上面的牌
    //骰子 摞牌
    public int staySid;
    public int stayCount;
    public int diceOne;
    public int diceTwo;
    //CardList
    public List<int> CardList;
    //吃杠碰胡
    public List<MahjongSpecialCardItem> mahjongSpecialCardItem = new List<MahjongSpecialCardItem>();
    public List<MahjongSpecialList> mahjongDoneSpecialCard = new List<MahjongSpecialList>(); //Done 特殊牌

    

    //其他定义
    //是否切换账号
    public bool SwitchAccount = false;
    //音乐状态
    public bool bgMusic = true;

    public bool effectMusic = true;

    //LOG提示
    public string logMsg;
    //其他玩家在进入准备界面后是否可以点击backUI 判断当前本人是不是庄家
    public bool OtherCanClick = false;
    //首次进入(不掉线的情况下加载玩家位置)
    public bool FirstLoadUser = false;
    //玩家的正常出牌（NORMAL）和吃杠碰胡出牌（ONLY_OUT_CARD）[玩家正常出牌和吃杠碰胡以后所发送消息用到的ActionType]
    public MAHJONG_ACTION_TYPE tempMahjongActionType { get; set; }

    public UserKickOutMessage userKickOutMessage;

    //重连次数
    public int RecentTimes;
    //是否游戏中重连
    public bool gameRecent = false;

    //音乐加载控制
    public int musicControl { get; set; }

    //胡的牌
    public int HuCard;
    public int Huseatid;
    public MAHJONG_ACTION_TYPE whatHu;
    //重连听牌
    public List<int> tingCards;

    //是否用特殊牌  这时候不能点击出牌按钮
    public bool havaSpecailCard { get; set; }

   
    //加载房间信息
    public void LoadRoomMsg(Dictionary<int, int> dicLimit, Dictionary<int, int> dicBaseScore, Dictionary<int, int> dicMaxScore, ulong ts)
    {
        dicRoomEnterLimit = dicLimit;
        dicRoomBaseScore = dicBaseScore;
        dicRoomBaseMaxScore = dicMaxScore;
        TimeStamp = ts;
    }

    #region 辅助计算

    
    public List<int> tempList = new List<int>();
    public void LoadIndex(int tDownIndex)
    {
        /*-玩家显示-*/        
        int RightIndex=0;
        int TopIndex=0;
        int LeftIndex=0;
        #region 判断其他玩家生成位置逆时针出牌
        //判断其他玩家生成位置
        if (tDownIndex == 1 || tDownIndex == 0)  //不加DownIndex==0需要在创建房间成功时候把自己的信息存入EginUser里面的OtherUser信息里面
        {
            RightIndex = 2;
            TopIndex = 3;
            LeftIndex = 4;
        }
        else if (tDownIndex == 2)
        {
            RightIndex = 3;
            TopIndex = 4;
            LeftIndex = 1;
        }
        else if (tDownIndex == 3)
        {
            RightIndex = 4;
            TopIndex = 1;
            LeftIndex = 2;
        }
        else if (tDownIndex == 4)
        {
            RightIndex = 1;
            TopIndex = 2;
            LeftIndex = 3;
        }
        tempList.Clear();
        tempList.Add(tDownIndex);
        tempList.Add(RightIndex);
        tempList.Add(TopIndex);
        tempList.Add(LeftIndex);
        Debug.Log(tempList[0] + ".." + tempList[1] + ".." + tempList[2] + ".." + tempList[3] + "..");
        #endregion 判断其他玩家生成位置逆时针出牌
    }

    public int returnOtherSeatIndex(int seatid)
    {
        int tempReture = 0;
        for (int i = 0; i < tempList.Count; i++)
        {
            if (seatid == tempList[i])
            {
                tempReture = i + 1;
                break;
            }
        }

        return tempReture;
    }
    #endregion

}
